package cn.udrm.water.base.v1.manager.restful;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.udrm.water.base.v1.commons.models.ResponseParam;
import cn.udrm.water.base.v1.manager.dto.BasePersonDto;
import cn.udrm.water.base.v1.manager.service.BasePersonService;

@RestController
@RequestMapping(value="v1/restful/person")
public class BasePersonRestful {
	@Autowired
	private BasePersonService personService;
	
	@GetMapping(value="getWithRoles/{id}")
	public ResponseParam<BasePersonDto> getWithRoles(@PathVariable(value="id") String id) {
		BasePersonDto personDto = personService.getWithRoles(id);
		return new ResponseParam<BasePersonDto>("数据获取成功", 200, personDto);
	}
	
	@PostMapping(value="save")
	public ResponseParam<BasePersonDto> save(@RequestBody BasePersonDto personDto) {
		BasePersonDto save = personService.save(personDto);
		return new ResponseParam<BasePersonDto>("数据保存成功", 200, save);
	}
	
	@PostMapping(value="update")
	public ResponseParam<BasePersonDto> update(@RequestBody BasePersonDto personDto) {
		BasePersonDto update = personService.update(personDto);
		return new ResponseParam<BasePersonDto>("数据保存成功", 200, update);
	}
	
	@GetMapping(value="getSelfById/{id}")
	public ResponseParam<BasePersonDto> getSelfById(@PathVariable(value="id") String id) {
		BasePersonDto selfById = personService.getSelfById(id);
		return new ResponseParam<BasePersonDto>("数据获取成功", 200, selfById);
	}

}
